package util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class DBUtils {
    private static Session currentSession = null;
    private static SessionFactory sessionFactory = null;
    public static Session getCurrentSession(){

        if(currentSession == null){
            synchronized (DBUtils.class){
                if(currentSession==null){
                    currentSession = getSessionFactory().getCurrentSession();
                }
            }
        }
        return currentSession;
    }
    public static SessionFactory getSessionFactory(){
        if(sessionFactory == null){
            synchronized (DBUtils.class){
                if(sessionFactory==null){
                    sessionFactory = new Configuration().configure().buildSessionFactory();
                }
            }
        }
        return sessionFactory;
    }
}
